#pragma once

#include "function.h"

namespace  ldl
{
namespace core
{
template<typename T>
class Mul : public Function<T>
{
public:
    Mul() {
        Function<T>::m_inputs.resize(2);
        Function<T>::m_outputs.resize(1);
        Function<T>::m_outputs[0] = std::make_shared<Tensor<T>>();
    }

    virtual ~Mul() = default;

    virtual void forward() override {
        Function<T>::m_outputs[0]->data() = Function<T>::m_inputs[0]->data() * Function<T>::m_inputs[1]->data();
    }
    virtual void backward() override {
        Function<T>::m_inputs[0]->grad() += Function<T>::m_inputs[1]->data() * Function<T>::m_outputs[0]->grad();
        Function<T>::m_inputs[1]->grad() += Function<T>::m_inputs[0]->data() * Function<T>::m_outputs[0]->grad();
    }
};
}
}
